import 'package:safetymonitor/generated/json/base/json_convert_content.dart';
import 'package:safetymonitor/app/data/entities/auth/login_entity.dart';

LoginEntity $LoginEntityFromJson(Map<String, dynamic> json) {
  final LoginEntity loginEntity = LoginEntity();
  final int? userId = jsonConvert.convert<int>(json['userId']);
  if (userId != null) {
    loginEntity.userId = userId;
  }
  final String? accessToken = jsonConvert.convert<String>(json['accessToken']);
  if (accessToken != null) {
    loginEntity.accessToken = accessToken;
  }
  final String? refreshToken = jsonConvert.convert<String>(json['refreshToken']);
  if (refreshToken != null) {
    loginEntity.refreshToken = refreshToken;
  }
  final int? expiresTime = jsonConvert.convert<int>(json['expiresTime']);
  if (expiresTime != null) {
    loginEntity.expiresTime = expiresTime;
  }
  final LoginCompanyInfo? companyInfo = jsonConvert.convert<LoginCompanyInfo>(json['companyInfo']);
  if (companyInfo != null) {
    loginEntity.companyInfo = companyInfo;
  }
  final List<LoginAppMenuCodes>? appMenuCodes = (json['appMenuCodes'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<LoginAppMenuCodes>(e) as LoginAppMenuCodes).toList();
  if (appMenuCodes != null) {
    loginEntity.appMenuCodes = appMenuCodes;
  }
  return loginEntity;
}

Map<String, dynamic> $LoginEntityToJson(LoginEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['userId'] = entity.userId;
  data['accessToken'] = entity.accessToken;
  data['refreshToken'] = entity.refreshToken;
  data['expiresTime'] = entity.expiresTime;
  data['companyInfo'] = entity.companyInfo.toJson();
  data['appMenuCodes'] = entity.appMenuCodes.map((v) => v.toJson()).toList();
  return data;
}

extension LoginEntityExtension on LoginEntity {
  LoginEntity copyWith({
    int? userId,
    String? accessToken,
    String? refreshToken,
    int? expiresTime,
    LoginCompanyInfo? companyInfo,
    List<LoginAppMenuCodes>? appMenuCodes,
  }) {
    return LoginEntity()
      ..userId = userId ?? this.userId
      ..accessToken = accessToken ?? this.accessToken
      ..refreshToken = refreshToken ?? this.refreshToken
      ..expiresTime = expiresTime ?? this.expiresTime
      ..companyInfo = companyInfo ?? this.companyInfo
      ..appMenuCodes = appMenuCodes ?? this.appMenuCodes;
  }
}

LoginCompanyInfo $LoginCompanyInfoFromJson(Map<String, dynamic> json) {
  final LoginCompanyInfo loginCompanyInfo = LoginCompanyInfo();
  final String? companyCode = jsonConvert.convert<String>(json['companyCode']);
  if (companyCode != null) {
    loginCompanyInfo.companyCode = companyCode;
  }
  final int? companyId = jsonConvert.convert<int>(json['companyId']);
  if (companyId != null) {
    loginCompanyInfo.companyId = companyId;
  }
  final String? companyName = jsonConvert.convert<String>(json['companyName']);
  if (companyName != null) {
    loginCompanyInfo.companyName = companyName;
  }
  final bool? isHead = jsonConvert.convert<bool>(json['isHead']);
  if (isHead != null) {
    loginCompanyInfo.isHead = isHead;
  }
  return loginCompanyInfo;
}

Map<String, dynamic> $LoginCompanyInfoToJson(LoginCompanyInfo entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['companyCode'] = entity.companyCode;
  data['companyId'] = entity.companyId;
  data['companyName'] = entity.companyName;
  data['isHead'] = entity.isHead;
  return data;
}

extension LoginCompanyInfoExtension on LoginCompanyInfo {
  LoginCompanyInfo copyWith({
    String? companyCode,
    int? companyId,
    String? companyName,
    bool? isHead,
  }) {
    return LoginCompanyInfo()
      ..companyCode = companyCode ?? this.companyCode
      ..companyId = companyId ?? this.companyId
      ..companyName = companyName ?? this.companyName
      ..isHead = isHead ?? this.isHead;
  }
}

LoginAppMenuCodes $LoginAppMenuCodesFromJson(Map<String, dynamic> json) {
  final LoginAppMenuCodes loginAppMenuCodes = LoginAppMenuCodes();
  final int? createTime = jsonConvert.convert<int>(json['createTime']);
  if (createTime != null) {
    loginAppMenuCodes.createTime = createTime;
  }
  final int? updateTime = jsonConvert.convert<int>(json['updateTime']);
  if (updateTime != null) {
    loginAppMenuCodes.updateTime = updateTime;
  }
  final String? creator = jsonConvert.convert<String>(json['creator']);
  if (creator != null) {
    loginAppMenuCodes.creator = creator;
  }
  final String? updater = jsonConvert.convert<String>(json['updater']);
  if (updater != null) {
    loginAppMenuCodes.updater = updater;
  }
  final bool? deleted = jsonConvert.convert<bool>(json['deleted']);
  if (deleted != null) {
    loginAppMenuCodes.deleted = deleted;
  }
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    loginAppMenuCodes.id = id;
  }
  final String? appMenuNameCode = jsonConvert.convert<String>(json['appMenuNameCode']);
  if (appMenuNameCode != null) {
    loginAppMenuCodes.appMenuNameCode = appMenuNameCode;
  }
  final int? roleId = jsonConvert.convert<int>(json['roleId']);
  if (roleId != null) {
    loginAppMenuCodes.roleId = roleId;
  }
  final dynamic userId = json['userId'];
  if (userId != null) {
    loginAppMenuCodes.userId = userId;
  }
  final dynamic roleOrUser = json['roleOrUser'];
  if (roleOrUser != null) {
    loginAppMenuCodes.roleOrUser = roleOrUser;
  }
  return loginAppMenuCodes;
}

Map<String, dynamic> $LoginAppMenuCodesToJson(LoginAppMenuCodes entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['createTime'] = entity.createTime;
  data['updateTime'] = entity.updateTime;
  data['creator'] = entity.creator;
  data['updater'] = entity.updater;
  data['deleted'] = entity.deleted;
  data['id'] = entity.id;
  data['appMenuNameCode'] = entity.appMenuNameCode;
  data['roleId'] = entity.roleId;
  data['userId'] = entity.userId;
  data['roleOrUser'] = entity.roleOrUser;
  return data;
}

extension LoginAppMenuCodesExtension on LoginAppMenuCodes {
  LoginAppMenuCodes copyWith({
    int? createTime,
    int? updateTime,
    String? creator,
    String? updater,
    bool? deleted,
    int? id,
    String? appMenuNameCode,
    int? roleId,
    dynamic userId,
    dynamic roleOrUser,
  }) {
    return LoginAppMenuCodes()
      ..createTime = createTime ?? this.createTime
      ..updateTime = updateTime ?? this.updateTime
      ..creator = creator ?? this.creator
      ..updater = updater ?? this.updater
      ..deleted = deleted ?? this.deleted
      ..id = id ?? this.id
      ..appMenuNameCode = appMenuNameCode ?? this.appMenuNameCode
      ..roleId = roleId ?? this.roleId
      ..userId = userId ?? this.userId
      ..roleOrUser = roleOrUser ?? this.roleOrUser;
  }
}